package com.yuebanmaoshare.file.ufop.factory;

import com.yuebanmaoshare.file.ufop.constant.StorageTypeEnum;
import com.yuebanmaoshare.file.ufop.domain.ThumbImage;
import com.yuebanmaoshare.file.ufop.operation.copy.Copier;
import com.yuebanmaoshare.file.ufop.operation.copy.product.*;
import com.yuebanmaoshare.file.ufop.operation.delete.Deleter;
import com.yuebanmaoshare.file.ufop.operation.delete.product.*;
import com.yuebanmaoshare.file.ufop.operation.download.Downloader;
import com.yuebanmaoshare.file.ufop.operation.download.product.*;
import com.yuebanmaoshare.file.ufop.operation.preview.Previewer;
import com.yuebanmaoshare.file.ufop.operation.preview.product.*;
import com.yuebanmaoshare.file.ufop.operation.read.Reader;
import com.yuebanmaoshare.file.ufop.operation.read.product.*;
import com.yuebanmaoshare.file.ufop.operation.upload.Uploader;
import com.yuebanmaoshare.file.ufop.operation.upload.product.*;
import com.yuebanmaoshare.file.ufop.operation.write.Writer;
import com.yuebanmaoshare.file.ufop.operation.write.product.*;
import com.yuebanmaoshare.file.ufop.autoconfiguration.Properties;

import javax.annotation.Resource;

public class UFOPFactory {
    private String storageType;
    private ThumbImage thumbImage;

    public UFOPFactory() {
    }

    public UFOPFactory(Properties Properties) {
        this.storageType = Properties.getStorageType();
        this.thumbImage = Properties.getThumbImage();
    }

    public Uploader getUploader() {

        int type = Integer.parseInt(storageType);
        Uploader uploader = null;
        if (StorageTypeEnum.LOCAL.getCode() == type) {
            uploader = new LocalStorageUploader();
        }
        return uploader;
    }


    public Downloader getDownloader(int storageType) {
        Downloader downloader = null;
        if (StorageTypeEnum.LOCAL.getCode() == storageType) {
            downloader = new LocalStorageDownloader();
        }
        return downloader;
    }


    public Deleter getDeleter(int storageType) {
        Deleter deleter = null;
        if (StorageTypeEnum.LOCAL.getCode() == storageType) {
            deleter = new LocalStorageDeleter();
        }
        return deleter;
    }

    public Reader getReader(int storageType) {
        Reader reader = null;
        if (StorageTypeEnum.LOCAL.getCode() == storageType) {
            reader = new LocalStorageReader();
        }
        return reader;
    }

    public Writer getWriter(int storageType) {
        Writer writer = null;
        if (StorageTypeEnum.LOCAL.getCode() == storageType) {
            writer = new LocalStorageWriter();
        }
        return writer;
    }

    public Previewer getPreviewer(int storageType) {
        Previewer previewer = null;
        if (StorageTypeEnum.LOCAL.getCode() == storageType) {
            previewer = new LocalStoragePreviewer(thumbImage);
        }
        return previewer;
    }

    public Copier getCopier() {
        int type = Integer.parseInt(storageType);
        Copier copier = null;
        if (StorageTypeEnum.LOCAL.getCode() == type) {
            copier = new LocalStorageCopier();
        }
        return copier;
    }
}
